function smallImg(imgID)
{
    var id = imgID;
    // console.log(id);
    $(".productImg_big").children().attr("src","img/productSingle/"+id+".jpg");
};
$(function () {
   var imgs = $(".productImg_small").children();
   imgs.each(
       function(){
           $(this).mouseenter(
               function(){
                   smallImg($(this).attr("imgID"));
                   // console.log($(this).attr("imgID"))
               }

           );

       });
   var big = $(".productImg_big").children();
   big.on("onload",
       function () {
       console.log("1");
           imgs.each(
               function() {
                   var id = $(this).attr("imgID");
                   var url = "img/productSingle/"+id+".jpg";
                   console.log(".."+url);
                   // console.log($(this).attr("imgID"))
                    var image = new Image();
                    image.attr("src",url);
                    var div = $("#loadImg");
                    image.onload = function () {
                            console.log(url);
                            div.appendChild($(image));
                        };

               }
                   );
       }
   );
    var up = $("#numberUp");
    var down = $("#numberDown");
    var number = $("#number").children();
    var maxNumber = parseInt($("#maxNumber").text());
    var numberValue = parseInt(number.val());
    number.keyup(
        function () {
            var num =  parseInt(number.val());
            if (isNaN(num))
                num = 1;
            if(num<0)
                num = 0;
            if(num>maxNumber)
                num = maxNumber;
            numberValue = num;
            number.val(numberValue);
        }
    );
    up.click(
        function () {
            console.log(numberValue);
            numberValue++;
            if(numberValue>=maxNumber)
                numberValue = maxNumber;
            number.val(numberValue);
        }
    );
    down.click(
        function () {
            console.log(numberValue);

            numberValue--;
            if(numberValue<=0)
                numberValue = 0;
            number.val(numberValue);
        }
    );
    var title = $(".product_nav").children();
    title .click(
        function () {
            var className = $(this).attr("class").split(" ");
            //
            if("product_navTitle"==className[0])
            {
                $(".product_access").hide();
                $(".product_detail").show();
            }
            else
            {
                $(".product_detail").hide();
                $(".product_access").show();
            }


          console.log(className[0]);
        }
    );
    $(".product_Info_buy").click(
        function () {
            var url = "forecheckLogin";
            var button = $(this).children();
            $.get(
                url,
                function (data) {
                    if(data=="fail")
                    {
                        $("#myModal").modal('show');

                    }
                    else
                    {
                        var num = $(".my_number").val();
                        location.href =  button.attr("href")+"&num="+num;
                    }
                }
            );
            return false;
        }
    );
    $(".product_Info_shop").click(
        function () {
            var url = "forecheckLogin";
            var button = $(this);

            $.get(
                url,
                function (data) {
                    if(data=="fail")
                    {
                        $("#myModal").modal('show');

                    }
                    else
                    {
                        var num = $(".my_number").val();
                        var pid = button.attr("pid");
                        var page = "foreaddCart";
                        $.post(
                            page,
                            {
                                "num":num,
                                "pid":pid
                            },
                            function (data) {
                                if(data=="success")
                                {
                                    button.html("已加入购物车");
                                    button.attr("disabled","disabled");
                                    button.css("background-color","lightgray");
                                    button.css("border-color","lightgray");
                                    button.css("color","black");

                                }
                            }

                        );
                    }
                }
            );
            return false;
        }
    );
});